layui.define(['form', 'table'], function(exports){
  var $ = layui.$,table = layui.table,form = layui.form;

  var memberId =$('input[name="id"]').val();

    table.render({
        elem: '#LAY-table'
        ,url: layui.setter.webRoot + '/member/wallet/operate/list.data'
        ,where:{memberId:memberId}
        ,method: 'post'
        ,parseData: function (res) {
            return {
                "code": res.code,
                "msg": res.msg,
                "count": res.body.total,
                "data": res.body.data
            };
        }
        ,response: {statusCode: 200}
        ,cols: [[
            {field: 'createDate',title: '时间'}
            ,{field: 'typeName',title: '操作类型'}
            ,{field: 'moneyTypeName', title: '类型'}
            ,{field: 'money', title: '金额',templet:function (record){
                if(record.moneyType == 3){
                    return record.money;
                }else{
                    return record.moneyStr + '元';
                }
            }}
            ,{field: 'operator', title: '操作用户',templet:function (record){
                return '【'+record.operatorTypeName+'】' + record.operator;
                }}
            ,{field: 'operateNote', title: '操作说明'}
        ]]
        ,page: true
        ,height: 'full'
        ,text: '对不起，加载出现异常！'
    });

    var active = {
        unfreeze:function (){
            layer.open({
                type: 2
                ,title: '解冻金额'
                ,content: layui.setter.webRoot + '/member/wallet/unfreeze.html?memberId='+memberId
                ,maxmin: true
                ,area: ['400px', '300px']
                ,btn: ['确定', '取消']
                ,yes: function(index, layero){
                    var iframeWindow = window['layui-layer-iframe'+ index]
                        ,submitID = 'LAY-form-submit',submit = layero.find('iframe').contents().find('#'+ submitID);
                    iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                        var field = data.field;
                        $.ajax({
                            type: "post",
                            url: layui.setter.webRoot + '/member/wallet/unfreeze.do',
                            data:field,
                            dataType:"json",
                            success:function(res){
                                if(res.code == 200){
                                    layer.close(index);
                                    location.reload();
                                }else{
                                    layer.msg(res.msg,{icon: 2});
                                }
                            }
                        });
                    });
                    submit.trigger('click');
                }
            });
        }
    }

    $('.layui-btn.LAY-btn-fun').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    table.on('tool(LAY-table)', function(obj){
        var type = obj.event ;
        active[type] ? active[type].call(this,obj) : '';
    });
  
  exports('member_wallet_info', {})
});